package club.cearnach.core.enumeration;

import java.util.HashMap;
import java.util.Map;

/**
 * 星座枚举
 *
 * @author 阮胜
 * @date 2018/5/12 22:45
 */
public enum ConstellationEnum {
    ARIES("白羊座", 0), TAURUS("金牛座", 1), GEMINI("双子座", 2), CANCER("巨蟹座", 3), LEO("狮子座", 4),
    VIRGO("处女座", 5), LIBRA("天秤座", 6), SCORPIO("天蝎座", 7), SAGITTARIUS("射手座", 8), CAPRICORN("摩羯座", 9),
    AQUARIUS("水瓶座", 10), PISCES("双鱼座", 11);

    private static final String[] NAMES;
    private static final Map<String, Integer> CONSTELLATION_MAP;

    static {
        ConstellationEnum[] values = ConstellationEnum.values();
        NAMES = new String[values.length];
        CONSTELLATION_MAP = new HashMap<>(values.length);
        for (int i = 0; i < values.length; i++) {
            ConstellationEnum value = values[i];
            String name = value.getName();
            NAMES[i] = name;
            CONSTELLATION_MAP.put(name, i);
        }
    }



    private String name;
    private int code;

    ConstellationEnum(String name, int code) {
        this.name = name;
        this.code = code;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public static String getConstellationName(int code) {
        return code > 0 && code < NAMES.length ? NAMES[code] : null;
    }

    public static int getConstellationCode(String name) {
        return CONSTELLATION_MAP.get(name);
    }

}
